package com.ruoyi.product.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.product.domain.GoodsOrders;
import com.ruoyi.product.service.IGoodsOrdersService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 订单管理Controller
 *
 * @author kzc
 * @date 2023-04-26
 */
@RestController
@RequestMapping("/manage/orders")
public class GoodsOrdersController extends BaseController
{
    @Autowired
    private IGoodsOrdersService goodsOrdersService;

    /**
     * 查询订单管理列表
     */
    @PreAuthorize("@ss.hasPermi('manage:orders:list')")
    @GetMapping("/list")
    public TableDataInfo list(GoodsOrders goodsOrders)
    {
        startPage();
        List<GoodsOrders> list = goodsOrdersService.selectGoodsOrdersList(goodsOrders);
        return getDataTable(list);
    }

    /**
     * 订单退款后同意
     */
    @PreAuthorize("@ss.hasPermi('manage:orders:refund')")
    @GetMapping("/refund/{id}")
    public AjaxResult refund(@PathVariable Integer id)
    {
        int upstaf = goodsOrdersService.upstaf(id);
        if (upstaf!=0)
            return AjaxResult.success("成功");
        else
            return AjaxResult.success("失败");
    }

    /**
     * 订单退款拒绝
     */
    @PreAuthorize("@ss.hasPermi('manage:orders:refund')")
    @GetMapping("/refundt/{id}")
    public AjaxResult refundt(@PathVariable Integer id)
    {
        int upstaf = goodsOrdersService.upstaf(id);
        if (upstaf!=0)
            return AjaxResult.success("成功");
        else
            return AjaxResult.success("失败");
    }

    /**
     * 导出订单管理列表
     */
    @PreAuthorize("@ss.hasPermi('manage:orders:export')")
    @Log(title = "订单管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GoodsOrders goodsOrders)
    {
        List<GoodsOrders> list = goodsOrdersService.selectGoodsOrdersList(goodsOrders);
        ExcelUtil<GoodsOrders> util = new ExcelUtil<GoodsOrders>(GoodsOrders.class);
        util.exportExcel(response, list, "订单管理数据");
    }

    /**
     * 获取订单管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:orders:query')")
    @GetMapping(value = "/{sgoId}")
    public AjaxResult getInfo(@PathVariable("sgoId") Integer sgoId)
    {
        return success(goodsOrdersService.selectGoodsOrdersBySgoId(sgoId));
    }

    /**
     * 新增订单管理
     */
    @PreAuthorize("@ss.hasPermi('manage:orders:add')")
    @Log(title = "订单管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GoodsOrders goodsOrders)
    {
        return toAjax(goodsOrdersService.insertGoodsOrders(goodsOrders));
    }

    /**
     * 修改订单管理
     */
    @PreAuthorize("@ss.hasPermi('manage:orders:edit')")
    @Log(title = "订单管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GoodsOrders goodsOrders)
    {
        return toAjax(goodsOrdersService.updateGoodsOrders(goodsOrders));
    }

    /**
     * 删除订单管理
     */
    @PreAuthorize("@ss.hasPermi('manage:orders:remove')")
    @Log(title = "订单管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{sgoIds}")
    public AjaxResult remove(@PathVariable Integer[] sgoIds)
    {
        return toAjax(goodsOrdersService.deleteGoodsOrdersBySgoIds(sgoIds));
    }
}
